package org.zxp.thread.interrupt;

import org.junit.Test;

/**
 * @program: zxp-thread-test
 * @description: stop方式比较粗暴，直接停，但是finally还是能被执行的
 * @author: X-Pacific zhang
 * @create: 2019-05-07 17:27
 **/
public class StopTest {
    @Test
    public void testStop(){
        Thread thread = new Thread(() -> {
            try{
                while(true){
                    System.out.println(sleep());
                }
            }finally {
                System.out.println("我被执行了");
            }
        });
        thread.start();
        sleep(5000L);
        thread.stop();
    }

    private String sleep(){
        try {
            Thread.sleep(1000L);
            return Thread.currentThread().getName();
        } catch (InterruptedException e) {
            e.printStackTrace();
            return "";
        }
    }

    private void sleep(long time){
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
